package stz.flash.main.strobe.field;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.TouchEvent;
import stz.flash.main.strobe.model.Strobe;
import blackberry.util.image.DjImageCalculator;
import blackberry.util.image.DjImageResizer;


public class MonkeyField extends BitmapFieldForStrobeMode {

	private static final int INDEX_OF_DARK_MONKEY = 0;
	private static final int INDEX_OF_BRIGHT_MONKEY = 1;
	
	
	private static final int leftLimit = DjImageCalculator.refineXIntoDisplay(
			120, 480, 800, DjImageCalculator.NONE);
	private static final int rightLimit = DjImageCalculator.refineXIntoDisplay(
			360, 480, 800, DjImageCalculator.NONE);
	private static int trimTopLimit = DjImageCalculator.refineYIntoDisplay(
			480, 480, 800, FIELD_TOP);
	
	public MonkeyField() {
		super(new Bitmap[] {
				DjImageResizer.fillIntoDisplay(
						Bitmap.getBitmapResource("Monkey_Dark.jpg"), 
						480, 800, 480, 800, Field.FIELD_TOP, Bitmap.FILTER_BILINEAR),
				
						DjImageResizer.fillIntoDisplay(
								Bitmap.getBitmapResource("Monkey_Bright.jpg"),
								480, 800, 480, 800, Field.FIELD_TOP, Bitmap.FILTER_BILINEAR)},
                FOCUSABLE);
		initFocusField(this);
	}

	public void execute() {
		Strobe.toggleStrobeFlash();
	}
	
	protected boolean outOfBounds(TouchEvent touchevent) {
		if (touchevent.getGlobalX(1) < leftLimit || touchevent.getGlobalX(1) > rightLimit 
				|| touchevent.getGlobalY(1) < trimTopLimit)
			return true;
		return false;
	}
	
	protected void onFocus(int i) {
		changeBitmapField(INDEX_OF_BRIGHT_MONKEY);
		super.onFocus(i);
	}
	
	protected void onUnfocus() {
		changeBitmapField(INDEX_OF_DARK_MONKEY);
		super.onUnfocus();
	}
}
